import JSEncrypt from 'jsencrypt'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = `
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0X3+wMoNd4W9UMS4zZZI
Kt8f6w8H4b1/QWqv9kwkd5ZDkw3888s2DpRcX8HN3yYe4w+w9pZXLtGUZafLUK/c
ah+T1SP6C/F3QTjWPtI9s4vpWp3OXGElnst2p0xwn+EKhuRHvKURE91tps7Fjikc
pZmYqVUJgO7poYiI+danWn/lQGB+ZyxQoEjqSr0ZLRVt2n0z8ib8Aq7itUA/tQoX
tTCY/bjsljrfF6RWLuS71LnpqdxtkX7EZ31WzkBjPZPpN0763G0DWgis7lg6OyDQ
ulUi9+MuhTQi/uwQfmsj/fYn+g+8vVxt0CKo1VwDj0LpfDtne8fvxYR4c8Op27Ia
6wIDAQAB
`

const privateKey = `
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDRff7Ayg13hb1Q
xLjNlkgq3x/rDwfhvX9Baq/2TCR3lkOTDfzzyzYOlFxfwc3fJh7jD7D2llcu0ZRl
p8tQr9xqH5PVI/oL8XdBONY+0j2zi+lanc5cYSWey3anTHCf4QqG5Ee8pRET3W2m
zsWOKRylmZipVQmA7umhiIj51qdaf+VAYH5nLFCgSOpKvRktFW3afTPyJvwCruK1
QD+1Che1MJj9uOyWOt8XpFYu5LvUuemp3G2RfsRnfVbOQGM9k+k3TvrcbQNaCKzu
WDo7INC6VSL34y6FNCL+7BB+ayP99if6D7y9XG3QIqjVXAOPQul8O2d7x+/FhHhz
w6nbshrrAgMBAAECggEAL64BgVd7YSyrPerINOJzYm6OES3GmXZLtFPX4LLLyfwF
PT79x28EyqSxsYmmlZdTiFJV8ImfJiTFJa3e9GpSPEUbnHMnwfgfMFUDTiEDsg2x
+tHX2eaybUXZp5IaQAk0ICdsvF7FWEQZZNHC3Ow2fOpMeJ3GH/ZAbmdo5ZQZWts/
MCNytS3V9+hKEVDAe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new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}
